<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Package_controller extends CI_Controller {

	function __construct()
	{
		parent::__construct();

		$this->load->model('package_model');
	}

	public function index()
	{
		$data['package_list'] = $this->package_model->get_all_by_user_id(1);
		$this->load->view('panel/package/index', $data);
	}

	public function show_create_form()
	{
		$this->load->model('service_model');
		$data['service_list'] = $this->service_model->get_all_enabled();
		$this->load->view('panel/package/create_package_form', $data);
	}

	public function create()
	{
		if(!$this->input->post()) redirect(PANEL_URL.'/package/show_create_form');

		$this->package_model->user_id = 1;
		$this->package_model->add_by_post($this->input->post());

		redirect(PANEL_URL . '/package');
	}

	public function supplier_list()
	{
		if(!$this->input->post()) {
			$this->output->set_content_type('application/json')
				    	 ->set_output(json_encode(array('error' => 'Invalid request')));
			return false;
		}

		$this->load->model('service_detail_model');
		$service_id = $this->input->post('service_id');
		$suppliers = $this->service_detail_model->get_all_by_service_id($service_id);
		$this->output->set_content_type('application/json')
				    	 ->set_output(json_encode($suppliers->result()));
	}

}

/* End of file package_controller.php */
/* Location: ./application/controllers/panel/package_controller.php */
